//package com.codejiwei.jdbc;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.collection.CollUtil;
//import cn.hutool.core.lang.Dict;
//import cn.hutool.core.util.ObjectUtil;
//import cn.hutool.core.util.ReflectUtil;
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.json.JSONUtil;
//import com.fasterxml.jackson.annotation.JsonProperty;
//import com.mchange.v2.c3p0.ComboPooledDataSource;
//import com.zyb.bigdata.common.annotation.Column;
//import com.zyb.bigdata.common.annotation.Pk;
//import com.zyb.bigdata.common.annotation.Table;
//import lombok.Data;
//import org.springframework.jdbc.core.BeanPropertyRowMapper;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
//
//import java.beans.PropertyVetoException;
//import java.lang.reflect.Field;
//import java.sql.*;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
///**
// * Author: jiwei01
// * Date: 2023/3/23 10:53
// * Package: com.codejiwei.jdbc
// * Description:
// */
//public class JdbcTest {
//    private static final String DB_URL = "jdbc:mysql://localhost:3306/test";
//    private static final String DB_USERNAME = "root";
//    private static final String DB_PASSWORD = "root";
//
//    public static JdbcTemplate jdbcTemplate = null;
//
//    public static void main(String[] args) throws PropertyVetoException {
//
//        // 建立连接
////        try (Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD)) {
////
////            // 创建statement对象
////            Statement stmt = conn.createStatement();
////
//////            // 执行插入操作
//////            String insertQuery = "INSERT INTO users (name, age) VALUES ('John', 25)";
//////            stmt.executeUpdate(insertQuery);
//////            System.out.println("插入成功！");
////
////            // 执行查询操作
////            String selectQuery = "SELECT * FROM test_tbl1";
////            ResultSet resultSet = stmt.executeQuery(selectQuery);
////
////
////
////            // 遍历查询结果
////            while (resultSet.next()) {
//////                int id = resultSet.getInt("id");
//////                String name = resultSet.getString("name");
//////                String versionTs = resultSet.getString("version_ts");
//////                System.out.println(id + " " + name + " " + versionTs);
////                BeanPropertyRowMapper<TestA> beanPropertyRowMapper = new BeanPropertyRowMapper<>();
////
////
////
////            }
////
////            // 关闭结果集和statement对象
////            resultSet.close();
////            stmt.close();
////
////        } catch (SQLException e) {
////            e.printStackTrace();
////        }
//
//
//
//
//
//        TestA testA = new TestA();
//        testA.setId(1);
//        testA.setName("Tom");
//        testA.setVersionTs(String.valueOf(System.currentTimeMillis()));
//
//
//
////        SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource)
////                .withTableName("test_tbl1")
////                .usingGeneratedKeyColumns("id")
////                .usingColumns("name", "version_ts");
////        Map<String, Object> params = new HashMap<>();
////        params.put("name", "zhaoliu");
////        params.put("version_ts", "ts0328");
//////        simpleJdbcInsert.execute(params);
////        Number number = simpleJdbcInsert.executeAndReturnKey(params);
////        System.out.println(number.intValue());
//
//
////        String sql ="insert ignore into test_tbl1 (name, version_ts) value ('jiwei', 'ts999')";
////        int update = jdbcTemplate.update(sql);
////        System.out.println(update);
//
//
////        String selectQuery = "SELECT * FROM test_tbl1";
//////        BeanPropertyRowMapper<TestA> rowMapper = new BeanPropertyRowMapper<>(TestA.class);
//////        TestA testA = jdbcTemplate.queryForObject(selectQuery,  rowMapper);
//////        System.out.println(testA);
////
////        Object[] myArray = new Object[0];
////        myArray = null;
////        List<Map<String, Object>> maps = jdbcTemplate.queryForList(selectQuery, myArray);
//
//
//
//
//
//
//
//
//
//    }
//
////    protected Integer insert(TestA t, Boolean ignoreNull,Boolean ignoreInsert) {
////        String table = getTableName(t);
////
////        List<Field> filterField = getField(t, ignoreNull);
////
////        List<String> columnList = getColumns(filterField);
////
////        String columns = StrUtil.join(Const.SEPARATOR_COMMA, columnList);
////
////        // 构造占位符
////        String params = StrUtil.repeatAndJoin("?", columnList.size(), Const.SEPARATOR_COMMA);
////
////        // 构造值
////        Object[] values = filterField.stream().map(field -> ReflectUtil.getFieldValue(t, field)).toArray();
////        String sql;
////        if (ignoreInsert) {
////            sql = StrUtil.format("INSERT ignore INTO {table} ({columns}) VALUES ({params})", Dict.create().set("table", table).set("columns", columns).set("params", params));
////
////        } else {
////            sql = StrUtil.format("INSERT INTO {table} ({columns}) VALUES ({params})", Dict.create().set("table", table).set("columns", columns).set("params", params));
////
////        }
////        return jdbcTemplate.update(sql, values);
////    }
//
//
//
//}
//@Data
//@Table(name = "test_tbl1")
//class TestA{
//    @Pk
//    public Integer id;
//
//    @Column(name = "name")
//    public String name;
//
//    @Column(name = "properties")
//    public Map<String, Object> properties;
//
//    @Column(name = "version_ts")
//    public String versionTs;
//}
//
//class TestB {
//
//    public void testUpdate(TestA testA) {
//        testA.setId(33);
//        testA.setName("zhangsa");
//        testA.setProperties(new HashMap<String, Object>());
//        testA.properties.put("aaa", "this is aaa");
//    }
//
//    public void testUpdate2(TestA testA) {
//        testA.setVersionTs("99999999");
//    }
//
//}